package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.analyse.AnalyseNews;
import com.kdtech.analyse.JSoupUtils;
import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.StringUtils;

/**
 * 东方卫视
 * @author Administrator
 * abc
 */
public class DragontvAnalyse implements AnalyseNews{
	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://www.dragontv.cn/(news|videos)/.*/[0-9a-zA-Z]{32}.html",
				"http://www.dragontv.cn/news/[a-z]*/[0-9a-z]*.html",
				"http://www.dragontv.cn/(news|videos)/.*/[0-9]+-[0-9]+-[0-9]+/[0-9]+.html",
                 "http://www.dragontv.cn/messages/indextomatonews/[0-9\\/\\-]+.html"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta video = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();
		if(!isDetailPage(url)){
		}
		video.setUrl(url);
		String title = null;
		String desc = null;
		String author = null;
		Long date = null;
		String dateStr = null;
		Document doc = Jsoup.parse(htmltxt);
		title = doc.select("div#newspageleftcontent >h1").text();

		desc = doc.select("div#nplayer").text();
		dateStr = doc.select("div#newspageleftcontent >h4").text();
		date = DateUtils.matchDate(dateStr);
		author = JSoupUtils.matchAuthor(doc, "来源:");
		video.setTitle(StringUtils.trimSpace(title));
		video.setContent(desc);
		video.setAuthor(author);
		video.setDate(date);
		return video;
	}
	

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}
	
}
